# 创建测试类
from selenium.webdriver.common.by import By
from selenium import webdriver
import time


class TestLogin(object):
    def setup_class(self):
        # 清理数据
        # 打开浏览器
        self.chrome = webdriver.Chrome()
        # 窗口最大化
        self.chrome.maximize_window()

    def setup_method(self):
        # 输入测试页面网址
        self.chrome.get("http://121.43.169.97:8081/common/member/login")

    # 登录成功
    try:
        def test01_success(self):
            # 测试步骤
            # 1、输入手机号码
            element = self.chrome.find_element(By.ID, "keywords").send_keys("18734494804")
            # 2、输入密码
            self.chrome.find_element(By.ID, "password").send_keys("www.13133")
            # 4、点击登录
            self.chrome.find_element(By.CLASS_NAME, "login-btn").click()
            time.sleep(2)
    except Exception as e:
        print(e)

    def teardown_methode(self):
        # 8、截图保存关键截图
        self.chrome.get_screenshot_as_file("../image/reg.png")
        # 9、断言
        # 等于 assert 预期结果 == 实际结果
        # 包含 assert 预期结果 in 实际结果
        assert "18734494804" in self.chrome.find_element(By.XPATH, "/html/body/div[1]/div[1]/div[1]/div/div[2]/li[1]/span/a").text

    def teardown_class(self):
        # 关闭浏览器
        time.sleep(3)
        self.chrome.quit()

